<?php 

class Zen_Option 
{
	
	private $_options = null;
	
	public function __construct($pattern=array(), $options = array()) {
		$this->_options = $pattern;
		
		if ($options instanceof Zend_Config) {
            $options = $options->toArray();
        }
        if (!is_array($options)) {
            throw new Exception("Options passed were not an array"
            . " or Zend_Config instance.");
        }
        while (list($name, $value) = each($options)) {
            $this->setOption($name, $value);
        }
        
	}
	
	public function setOption($name, $value)
    {
        if (!is_string($name)) {
            throw new Exception("Incorrect option name : $name");
        }
        $name = strtolower($name);
        if (array_key_exists($name, $this->_options)) {
            // This is a Core option
            $this->_options[$name] = $value;
        }
        return $this;
    }
    
	public function getOption($name)
    {
        if (is_string($name)) {
            $name = strtolower($name);
            if (array_key_exists($name, $this->_options)) {
                // This is a Core option
                return $this->_options[$name];
            }
            if (array_key_exists($name, $this->_specificOptions)) {
                // This a specic option of this frontend
                return $this->_specificOptions[$name];
            }
        }
        throw new Exception("Incorrect option name : $name");
    }
    
	public function setOptions($options = null)
    {
        foreach ($options as $key => $value) {
            $this->setOption($key, $value);
        }
        return $this;
    }
    
   	public function getOptions()
    {
        return $this->_options;
    }
	
}